package com.hongfasoft.wx.service;

import java.util.Calendar;

/**
 * 
 * 类描述：微信通用接口凭证
 * 
 * @author 王涛
 * @date 2014年12月7日
 */
public class AccessToken
{
	// 获取到的凭证
	private String token;
	// 凭证有效时间，单位：秒
	private int expiresIn;

	private long tookenGetTime;

	public void setTookenGetTime(long time)
	{
		this.tookenGetTime = time;
	}

	public String getToken()
	{
		return token;
	}

	public void setToken(String token)
	{
		this.token = token;
	}

	public int getExpiresIn()
	{
		return expiresIn;
	}

	public void setExpiresIn(int expiresIn)
	{
		this.expiresIn = expiresIn;
	}

	public synchronized boolean isAlive()
	{
		boolean isAlive = false;
		Calendar c = Calendar.getInstance();
		long now = c.getTimeInMillis();
		isAlive = (now - this.tookenGetTime) < this.expiresIn * 1000;
		return isAlive;
	}

	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		sb.append("token=" + this.token);
		sb.append("\r\n");
		sb.append("expiresIn=" + this.expiresIn);
		return sb.toString();
	}
}